﻿@model LeadMaster.ViewModels.ViewModelCompanies

<table class="listtable contactstable" cellspacing="0" cellpadding="0" style="width: 875px;">
<thead>
<tr>
<th>Description</th>
<th>Lead Question</th>
<th>Mandatory</th>
<th></th>
</tr>
</thead>
@{
    if (Model.ListCompanySundries != null && Model.ListCompanySundries.Count > 0)
	{
        foreach (var item in Model.ListCompanySundries)
        {
            <tr>
                <td><label class="selectsundry" data-sundryid="@(item.CompanySundriesID)" style="cursor: pointer; color: #333333;">@item.Description</label></td>
                <td><label>@item.LeadQuestion</label></td>
                <td><label>@item.MandatoryLeadQuestion</label></td>
                <td><img src="~/Images/delete.ico" style="width: 20px; height: 20px" class="deletesundry" data-sundry="@(item.CompanySundriesID)"/></td>
            </tr>
        }
    }
}
</table>

<input type="button" value="Add" id="addSundry" />

<div id="newsundry"></div>

<script type="text/javascript">
    $().ready(function () {

        $("#newsundry").dialog(
        {
            autoOpen: false,
            width: 900,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                save: function () {
                    $(this).dialog("close");
                    $("#formCompanySundry").submit();
                },
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

        $("#addSundry").click(function () {
            $('#newsundry').dialog("open");
            $('#newsundry').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("NewCompanySundry", "Leads"))/?CompanyID=@(ViewBag.CompanyID)';
            $('#newsundry').load(contactURL);
        });

        $(".deletesundry").click(function () {
            var ans = confirm("Are you sure you wish to delete this sundry ?")
            if (ans == true) {
                var contactURL = '@(Url.Action("DeleteSundry", "Leads"))/?id=' + $(this).data("sundry");
                $('#companysundries').load(contactURL);
            }
        });

        $(".selectsundry").click(function () {
            $("#newsundry").dialog("open");
            $('#newsundry').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("EditSundry", "Leads"))/?id=' + $(this).data("sundryid");
            $('#newsundry').load(contactURL);
        });

    });
</script>